﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Net;

namespace CSharp_Homework_8
{
    public partial class Form1 : Form
    {
        private delegate void MyDelegate();

        public Form1()
        {
            InitializeComponent();
        }

        private void Search_Click(object sender, EventArgs e)
        {
            Task task1 = new Task(() => { Baidu_Search1("https://baidu.com/baidu?wd=" + textBox1.Text); });
            Task task2 = new Task(() => { Baidu_Search2("https://baidu.com/baidu?wd=" + textBox1.Text); });
            task1.Start();
            task2.Start();
        }

        private void Baidu_Search1(string url)
        {
            WebClient web = new WebClient();
            byte[] downLoad = web.DownloadData(url);           //下载
            string data = Encoding.UTF8.GetString(downLoad);
            this.BeginInvoke(new MyDelegate(() => Show1.Text = data.Substring(0, 100)));
            //this.BeginInvoke(new MyDelegate(() => Show2.Text = data.Substring(0, 100)));
        }

        private void Baidu_Search2(string url)
        {
            WebClient web = new WebClient();
            byte[] downLoad = web.DownloadData(url);           //下载
            string data = Encoding.UTF8.GetString(downLoad);
            this.BeginInvoke(new MyDelegate(() => Show2.Text = data.Substring(0, 100)));
        }
    }
}
